$(function(){
	$("#questionbankadd").on('click',function(){
		$("#wjladd").window("open");
		$('#question_bankAdd_getDep').combobox({
		    url:'../exam/getAllDep',
		    valueField:'depId',
		    textField:'depName'
		});
	})
	// 定义底部保存，清空，取消按钮
	$('#wjladd').dialog({
		buttons : [ {
			text : '保存',
			iconCls : 'icon-save',
			handler : function() {
				$('#ff').form('submit', {
					url:"../exam/addquestionBank",
					onSubmit : function(param) {
						$("#wjladd").window("close");
					},
					success : function(data) {
						alert(data)
					}
				});

			}
		}, {
			text : '清空',
			iconCls : 'icon-clear',
			handler : function() {
				$('#ff').form('clear');
			}
		}, {
			text : '取消',
			iconCls : 'icon-cancel',
			handler : function() {
				$("#wjladd").window("close");
			}
		} ]
	});
	$("#qusetion_bank_getDep").combobox({
	    url:'../exam/getAllDep',
	    valueField:'depId',
	    textField:'depName'
	});
	
	$('#qbtab').datagrid({
	    url:'../exam/getAllQuestionBank',
	    columns:[[
			{field:'qbId',title:"编号",width:70,align:'center',
				formatter: function(value,row,index){
			        return '<a style="color:blue" onClick="wjl_show_qb_info('+row.qbId+')">'+value+'</a>';
			    }
			},
			{field:'qbName',title:"题库",width:140,align:'center'},
			{field:'dep_id',title:"部门",width:70,align:'center',
				formatter: function(value,row,index){
					if (row.dep){
						return row.dep.depName;
					} else {
						return value;
					}
				}},
			{field:'singleChoiceNum',title:"单选数",width:70,align:'center'},
			{field:'multiselectNum',title:"多选数",width:70,align:'center'},
			{field:'judgeNum',width:70,title:"判断数",align:'center'},
			{field:'fillNum',title:"填空数",width:70,align:'center'},
			{field:'syntheticalNum',title:"综合数",width:70,align:'center'},
			{field:'createPeople',title:"创建人",width:80,align:'center'},
			{field:'createDate',title:"创建时间",width:150,align:'center'},
			{field:'attr8',width:100,align:'center'}
	    ]],
		fit:true,
		singleSelect:true,
		method:'get',
		toolbar:'#qusetion_bank_tb',
		rownumbers:true,
		width: 700,
		height: 250,
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:5,
		//可选的每页大小
		pageList:[2,5,8],
	});
	$("#questionBank_search").bind('click',function(){
		var dep=$("#qusetion_bank_getDep").val();
		var qbName=$("input[name='questionBank']").val();
		alert(dep+" "+qbName)
		/*$.post('../exam/getQuestionBank_Search',{'depName':dep,'qbName':qbName},function(e){
			if(e.success){
				$.messager.show({
					title:'成功',
					msg:e.msg,
				});
				
			}else{
				$.messager.alert('错误',e.msg,'error');
			}
		})*/
		$('#qbtab').datagrid('load','../exam/getQuestionBank_Search?depId='+ dep +'&qbName='+qbName+' ');
		
	});

	
});
function wjl_show_qb_info(qbId){
	console.log(qbId);
	$("#tt").tabs('getTab','题库').panel('open').panel('refresh','../exam/questionbankInfo?qbId='+qbId);
}